package cq.zhcqk.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import cq.zhcqk.R;
import cq.zhcqk.entity.AXSTBean;

/**
 * Created by zhangle on 2018/3/3.
 */
public class AXSTRightAdapter extends BaseAdapter{
    List<AXSTBean> list;
    Context context;
    //当前Item被点击的位置
    private int currentItem;
    public AXSTRightAdapter(Context context, List<AXSTBean> list){
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list ==null?0:list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final viewHolder holder;
        if(convertView == null){
            holder = new viewHolder();
            convertView = View.inflate(context, R.layout.item_right_axst,null);
            holder.name = (TextView) convertView.findViewById(R.id.name);
            convertView.setTag(holder);
        }else{
            holder = (viewHolder) convertView.getTag();
        }

        if(currentItem == position){

        }
        AXSTBean info = list.get(position);
        holder.name.setText(info.getName());
        if (currentItem == position) {
            //如果被点击，设置当前TextView被选中
            System.out.println(currentItem);
            holder.name.setSelected(true);
        } else {
            //如果没有被点击，设置当前TextView未被选中
            holder.name.setSelected(false);
        }
        return convertView;
    }

    private class viewHolder{
        private TextView name;
    }

    public void setCurrentItem(int currentItem) {
        this.currentItem = currentItem;
    }
}
